#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>

using namespace std;
using LL = long long;

const int N = 2e5 + 10;

int n;
int cnt = 0;
int q[N];
int p1[N], p2[N];
LL dp[N];  //dp[n]代表前i个的数量


int bisearch(int k){
    int l = 0, r = cnt;
    while(l < r){
        int mid = ((l + r + 1) >> 1);
        if(p2[mid] < k){
            l = mid;
        }else{
            r = mid - 1;
        }
    }

    return l;
}

int main(){
    // ios::sync_with_stdio(false);
    // cin.tie(nullptr);
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    int T;
    cin >> T;
    while(T --){
        cnt = 0;
        memset(dp, 0, sizeof dp);
        cin >> n;

        for (int i = 1; i <= n; i ++){
            cin >> q[i];
        }

        for (int i = 1; i <= n; i ++){
            if(q[i] < i){
                cnt++;
                p1[cnt] = q[i];
                p2[cnt] = i;
            }
        }

        for (int i = 1; i <= cnt; i ++){
            int k = bisearch(p1[i]);
            dp[i] = dp[i - 1] + k;
        }

        printf("%lld\n", dp[cnt]);
    }

    return 0;
}